<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        当前的数字是{{ total }}
        <my-cpn @add="statusConut" @dec="statusConut"></my-cpn>
    </div>
    <template id="myCpn">
        <div>
            <button @click="add">+1</button>
            <button @click="dec">-1</button>
        </div>
    </template>
    <script src="../js/vue.js"></script>
    <script>
        const app = new Vue({
            el:'#app',
            data(){
                return {
                    total:0
                }
            },
            components:{
                'my-cpn':{
                    template:'#myCpn',
                    data(){
                        return{
                            conut:0
                        }
                    },
                    methods:{
                        add(){
                            this.conut++
                            this.$emit('add',this.conut)
                        },
                        dec(){
                            this.conut--
                            this.$emit('dec',this.conut)
                        }
                    }
                }
            },
            methods:{
                statusConut(val){
                    this.total = val
                }
            }
        })
    </script>
</body>
</html>